package com.eddie.principle.segregation.improve;

import lombok.extern.slf4j.Slf4j;

/**
 * @author Eddie
 * @date 2022/4/27 13:08
 */
public class Segregation1 {
    public static void main(String[] args) {
        A a = new A();
        //A类通过接口依赖B
        a.depend1(new B());
        a.depend2(new B());
        a.depend3(new B());
        C c = new C();
        //A类通过接口依赖D
        c.depend1(new D());
        c.depend4(new D());
        c.depend5(new D());

    }
}

interface Interface1 {
    void operation1();

}

interface Interface2 {
    void operation2();

    void operation3();
}


interface Interface3 {
    void operation4();

    void operation5();
}

@Slf4j
class B implements Interface1, Interface2 {

    @Override
    public void operation1() {
        log.info("B 实现了operation1");
    }

    @Override
    public void operation2() {
        log.info("B 实现了operation2");
    }

    @Override
    public void operation3() {
        log.info("B 实现了operation3");
    }
}

@Slf4j
class D implements Interface1, Interface3 {

    @Override
    public void operation1() {
        log.info("D 实现了operation1");
    }

    @Override
    public void operation4() {
        log.info("D 实现了operation4");
    }

    @Override
    public void operation5() {
        log.info("D 实现了operation5");
    }
}

/**
 * A类通过接口Interface1依赖（使用）B类，但是只会用到1，2，3方法
 */
class A {
    public void depend1(Interface1 i) {
        i.operation1();
    }

    public void depend2(Interface2 i) {
        i.operation2();
    }

    public void depend3(Interface2 i) {
        i.operation3();
    }
}

/**
 * C类通过接口Interface1依赖（使用）D类，但是只会用到1，4，5方法
 */
class C {
    public void depend1(Interface1 i) {
        i.operation1();
    }

    public void depend4(Interface3 i) {
        i.operation4();
    }

    public void depend5(Interface3 i) {
        i.operation5();
    }
}